package com.tencent.iov.cowin.befsale.clue.service.clue.impl;

import com.github.pagehelper.Page;
import com.tencent.iov.cowin.befsale.clue.domain.clue.po.ClueIntentionVehicle;
import com.tencent.iov.cowin.befsale.clue.repository.clue.ClueInitialIntentionVehicleManager;
import com.tencent.iov.cowin.befsale.clue.service.clue.ClueInitialIntentionVehicleService;
import com.software.boot.common.model.dao.PageRequest;
import com.software.boot.common.model.dao.PageResponse;
import com.software.boot.common.util.BeanUtil;
import com.software.boot.common.util.EmptyUtils;
import com.software.boot.common.util.ValidateUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Describe: 意向车车型_Service实现层
 * @author: zly
 * @created: 2022-01-06 14:53:45
 * @version: 1.0
 */
@Service
public class ClueInitialIntentionVehicleServiceImpl implements ClueInitialIntentionVehicleService {
	
	@Autowired
	private ClueInitialIntentionVehicleManager clueInitialIntentionVehicleManager;

	/**
	 * 通过ID获取详细信息
	 *
	 * @param: request
	 * @return: ClueIntentionVehicle对象
	 */
	@Override
	public ClueIntentionVehicle getDetailById(Long id){
		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(id, "请求参数不能为空");
		ValidateUtils.checkIntNotNullAndGTZero(id.intValue(), "ID不能为空或小于0");
		/** 2 处理业务 */
		ClueIntentionVehicle clueIntentionVehicle = clueInitialIntentionVehicleManager.getDetailById(id);
		if (EmptyUtils.isNotEmpty(clueIntentionVehicle)) {
			return BeanUtil.copy(clueIntentionVehicle, ClueIntentionVehicle.class);
		}
		/** 3 返回结果 */
		return null;
	}

	/**
	 * 单条数据插入ClueIntentionVehicle
	 * @param request
	 * @return 插入的条数
	 */
	@Override
	public int insert (ClueIntentionVehicle request){
		/** 1 验证请求参数 */
		/** 2 处理业务 */
		int count = clueInitialIntentionVehicleManager.insert(request);
		/** 3 封装返回值 */
		return count;
    }

	/**
	 * 批量插入ClueIntentionVehicle
	 * @param requests
	 * @return 批量插入的条数
	 */
	@Override
    public int insertBatch(List<ClueIntentionVehicle> requests){
		/** 1 验证请求参数 */
		/** 2 处理业务 */
		int count = clueInitialIntentionVehicleManager.insertBatch(requests);
		/** 3 封装返回值 */
		return count;
    }


	/**
	 * 单条ClueIntentionVehicle更新
	 * @param request
	 * @return 更新的条数
	 */
	@Override
    public int update(ClueIntentionVehicle request){
	
		/** 1 验证请求参数 */
		/** 2 处理业务 */
		int count = clueInitialIntentionVehicleManager.update(request);
		/** 3 返回对象 */
		return count;
    }

	/**
	 * 通过ID删除数据
	 * @param request
	 * @return 删除的条数
	 */
	@Override
	public int delete(ClueIntentionVehicle request){
		Long id = request.getId();
		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(id, "请求参数不能为空");
		ValidateUtils.checkIntNotNullAndGTZero(id.intValue(), "ID不能为空或小于0");
		/** 2 处理业务 */
		ClueIntentionVehicle clueIntentionVehicle = new ClueIntentionVehicle();
		clueIntentionVehicle.setId(id);
//		clueIntentionVehicle.setDelete(DeleteEnum.DETELED.getCode());
		int count = clueInitialIntentionVehicleManager.update(clueIntentionVehicle);
		/** 3 返回对象 */
		return count;
    }

	/**
	 * 根据条件查询对象对象list列表
	 * @param request
	 * @return 查询结果
	 */
	@Override
	public List<ClueIntentionVehicle> getListByParam(ClueIntentionVehicle request){
		/** 1 验证请求参数 */
		//可以设置排序
		/** 2 处理业务 */
		List<ClueIntentionVehicle> queryList = clueInitialIntentionVehicleManager.getListByParam(request);
		/** 3 返回结果 */
		if (CollectionUtils.isNotEmpty(queryList)) {
		return BeanUtil.copyByList(queryList, ClueIntentionVehicle.class);
		}
		return new ArrayList<>();
	}

	/**
	 * 根据条件查询对象list记录
	 * @param request
	 * @return 分页对象
	 */
	@Override
	public PageResponse<ClueIntentionVehicle> getPageByParam(PageRequest<ClueIntentionVehicle> request){
		/** 1 验证请求参数 */
		ValidateUtils.checkObjNull(request, "请求参数不能为空");
		//可以设置排序 query.orderByCreatedTime(true);
		/** 2 处理业务 */
		RowBounds rowBounds = new RowBounds(request.getPageNum(), request.getPageSize());
		Page<ClueIntentionVehicle> queryPageList = clueInitialIntentionVehicleManager.getPageByParam(request.getParamData(), rowBounds);
		PageResponse<ClueIntentionVehicle> pageResponse = new PageResponse<>();
		pageResponse.converPageResponse(pageResponse, queryPageList, request);
		pageResponse.setDataList(BeanUtil.copyByList(queryPageList.getResult(), ClueIntentionVehicle.class));
		/** 3 返回结果 */
		return pageResponse;
	}

	/**
	 * 根据条件查询单个对象
	 * @param request
	 * @return
	 */
	@Override
	public ClueIntentionVehicle getOneByParam(ClueIntentionVehicle request) {
		return clueInitialIntentionVehicleManager.getOneByParam(request);
	}

	/**
	 * 根据条件删除线索源品牌车系信息
	 * @param vehicleRequest
	 * @return
	 */
	@Override
	public Integer deleteByParam(ClueIntentionVehicle vehicleRequest) {
		return clueInitialIntentionVehicleManager.deleteByParam(vehicleRequest);
	}
}
